﻿using Domain.Entity;
using DtoFw;
using DtoFw.Query;
using Repository.Base;
using Util;

namespace Repository
{
    public class MainUserRepository : BaseRepository<MainUserEntity>
    {
        private readonly SnowFlakeGenerator worker;
        public MainUserRepository(SnowFlakeGenerator snowFlakeGenerator) : base(snowFlakeGenerator)
        {
            this.worker = snowFlakeGenerator;
        }
        /// <summary>
        /// 获取商务资源列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public Pager<MainUserEntity> GetPagerList(UserInfoQuery query,string organid)
        {
            var _orgid = query.OrganId;
            if (!string.IsNullOrEmpty(organid) && long.TryParse(organid,out _orgid))
            {

            }

            var organids = QueryOrgs(_orgid);
            return base.GetPager(query, linq =>
            {
                linq = linq.Where(t => !t.IsDeleted);
                if (!string.IsNullOrEmpty(query.Name))
                    linq = linq.Where(t => t.Name.Contains(query.Name));
                if (!string.IsNullOrEmpty(query.PoliceNo))
                    linq = linq.Where(t => t.PoliceNo == query.PoliceNo);
                if (!string.IsNullOrEmpty(query.UserNo))
                    linq = linq.Where(t => t.UserNo == query.UserNo);
                if (!string.IsNullOrEmpty(query.Phone))
                    linq = linq.Where(t => t.Phone == query.Phone);
                linq.Where(v=> organids.Contains(v.OrgId));
                return linq;
            });
        }
    }
}
